package com.demo.oauth2jFinalShiroServer.model;

import java.util.Date;
import java.util.Set;

public class OAuth2Entity {
	private String username; // 登录用户,code响应时赋值
	private String code; // code响应时赋值
	private Set<String> scopes; // code响应时赋值
	private Date codeStartTime = new Date(); // code响应时赋值
	private String clientId; // code响应时赋值
	private String accessToken; // accessToken响应时赋值
	private Long expireIn; // accessToken响应时赋值
	private Date tokenStartTime; // accessToken响应时赋值
	public static final Long CODE_EXPIREIN = 3* 60 * 1000L;

	public boolean isCodeExpired() {
		return CODE_EXPIREIN.compareTo(new Date().getTime() - codeStartTime.getTime()) < 0;
	}

	public boolean isTokenExpired() {
		if (expireIn == null || tokenStartTime==null) {
			return false;
		}
		return Long.valueOf(expireIn * 1000L).compareTo(new Date().getTime() - tokenStartTime.getTime()) < 0;
	}

	public void setExpireIn(Long expireIn) {
		this.expireIn = expireIn;
	}

	public void setTokenStartTime(Date tokenStartTime) {
		this.tokenStartTime = tokenStartTime;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Set<String> getScopes() {
		return scopes;
	}

	public void setScopes(Set<String> scopes) {
		this.scopes = scopes;
	}

	public String getClientId() {
		return clientId;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

	public String getAccessToken() {
		return accessToken;
	}

	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

}
